package UseStackToQueue;

import java.util.Stack;

public class MyQueue {
    public Stack<Integer> s1;//主
    public Stack<Integer> s2;//辅

    public MyQueue() {
        this.s1 = new Stack<>();
        this.s2 = new Stack<>();
    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        while (s1.size() > 1) {
            s2.push(s1.pop());
        }
        int ret = s1.pop();

        while (!s2.empty()) {
            s1.push(s2.pop());
        }

        return ret;
    }

    public int peek() {
        while (s1.size() > 0) {
            s2.push(s1.pop());
        }
        int ret = s2.peek();

        while (!s2.empty()) {
            s1.push(s2.pop());
        }

        return ret;
    }

    public boolean empty() {
        return this.s1.empty() && this.s2.empty();
    }
}
